package com.kmproject.haifu.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.RxUtils;
import com.kmproject.haifu.mvp.contract.HousePublishSelectTypeContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.PublishNumCheakBean;

import java.util.List;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 06/26/2019 10:42
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class HousePublishSelectTypePresenter extends BasePresenter<HousePublishSelectTypeContract.Model, HousePublishSelectTypeContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public HousePublishSelectTypePresenter(HousePublishSelectTypeContract.Model model, HousePublishSelectTypeContract.View rootView) {
        super(model, rootView);
    }

    /**
     * 校验是否可以发布
     */
    public void isPublishCount(){
        mModel.isPublishCount().compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<PublishNumCheakBean>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<PublishNumCheakBean> publishNumCheakBeanResultBean) {
                        if (AppUtil.isSuccess(publishNumCheakBeanResultBean))
                        {
                            mRootView.isPublishCountSuccess(publishNumCheakBeanResultBean.getData());
                        }else {
                            mRootView.showMessage(publishNumCheakBeanResultBean.getMessage());
                        }
                    }
                });
    }
    /**
     * 获取用户会员中心信息
     */
    public void getMemberLevelByUser() {
        mModel.getMemberLevelByUser().compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<MemberCenterUserInfoBean>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<MemberCenterUserInfoBean> memberCenterUserInfoBeanResultBean) {
                        if (AppUtil.isSuccess(memberCenterUserInfoBeanResultBean)) {
                            mRootView.getMemberLevelByUserSuccess(memberCenterUserInfoBeanResultBean.getData());
                        } else {
                            mRootView.showMessage(memberCenterUserInfoBeanResultBean.getMessage());
                        }
                    }
                });
    }
    /**
     * 获取租房发布类型
     * @param
     * @param
     */
    public void  dictList() {
        mModel.dictList(Api.HOUSE_CATEGORY,"").compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<List<HousePayWayBean>>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<List<HousePayWayBean>> listResultBean) {
                      if (AppUtil.isSuccess(listResultBean))
                      {
                          mRootView.dictListSuccess(listResultBean.getData());
                      }else {
                          mRootView.showMessage(listResultBean.getMessage());
                      }
                    }
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
